// <copyright file="Utils.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Core.Web
{
    using System;
    using System.Configuration;
    using System.Web;

    public class Utils
    {
        private static string _skinName;

        public static string SkinName
        {
            get
            {
                if (!string.IsNullOrEmpty(_skinName))
                {
                    return _skinName;
                }

                _skinName = ConfigurationManager.AppSettings["Skin"];
                return _skinName;
            }
        }

        public static string GetBaseUrl(string applicationPath, Uri url, bool appendTrailingSlash)
        {
            applicationPath = VirtualPathUtility.RemoveTrailingSlash(applicationPath);
            string baseUrl = string.Format("{0}://{1}{2}",
                                           url.Scheme,
                                           url.Authority,
                                           applicationPath);

            if (appendTrailingSlash)
            {
                return VirtualPathUtility.AppendTrailingSlash(baseUrl);
            }

            return VirtualPathUtility.RemoveTrailingSlash(baseUrl);
        }
    }
}